package com.itheima.demo.ZuoYe;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

//项目根路径下有个questions.txt文件内容如下：
//         5+5
////    150-25
////    155*155
////    2555/5
//    要求：读取内容计算出结果，将结果写入到results.txt文件中
//    5+5=10
public class jieGuo {
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new FileReader("D:\\作业结果.txt"));
        BufferedWriter bw=new BufferedWriter(new FileWriter("D:\\作业结果.txt"));
        ArrayList<String>list=new ArrayList<>();
        String len="";
        while ((len=br.readLine())!=null){
            list.add(len);
        }
        System.out.println(list);
        for (String s : list) {
            if (s.contains("+")){
                String[] split = s.split("\\+");
                int a = Integer.parseInt(split[0]);
                int b = Integer.parseInt(split[1]);
                int jian = jian(a, b);
                String c=split[0]+"+"+split[1]+"="+String.valueOf(jian);
                bw.write(c);
                bw.flush();

            }else if(s.contains("-")){
                String[] split = s.split("\\-");
                int a = Integer.parseInt(split[0]);
                int b = Integer.parseInt(split[1]);
                int add = add(a, b);
                String d=split[0]+"-"+split[1]+"="+String.valueOf(add);
                bw.write(d);
                bw.flush();

            }else if(s.contains("*")){
                String[] split = s.split("\\*");
                int a = Integer.parseInt(split[0]);
                int b = Integer.parseInt(split[1]);
                int chen = chen(a, b);
                String e=split[0]+"*"+split[1]+"="+String.valueOf(chen);
                bw.write(e);
                bw.flush();
            }else if (s.contains("/")){
                String[] split = s.split("\\/");
                int a = Integer.parseInt(split[0]);
                int b = Integer.parseInt(split[1]);
                int chu = chu(a, b);
                String f=split[0]+"/"+split[1]+"="+String.valueOf(chu);
                bw.write(f);
                bw.flush();

            }

        }
        br.close();
        bw.close();

        }

    private static int chu(int a,int b) {

        return a/b;
    }

    private static int chen(int a,int b) {
        return a*b;
    }

    private static int jian(int a,int b) {
        return a+b;
    }

    private static int add(int a,int b) {
        return a-b;
    }


}

